package com.qs.eggs.view.activity;


import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.qpg.paylib.PayAPI;
import com.qpg.paylib.WechatPayReq;
import com.qs.eggs.Constants;
import com.qs.eggs.R;
import com.qs.eggs.adapter.RecordAdapter;
import com.qs.eggs.base.activity.BaseActivity;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Response;

public class RechargeRecordActivity extends BaseActivity implements View.OnClickListener{
    private RecyclerView recycleView;
    private Toolbar back;
    private RecordAdapter recordAdapter;

    @Override
    protected int getContentView() {
        return R.layout.activity_recharge_record;
    }

    @Override
    protected void initWidget() {
        super.initWidget();

        recycleView=(RecyclerView)findViewById(R.id.recyclerview);
        recycleView.setLayoutManager(new LinearLayoutManager(this));
        back=(Toolbar)findViewById(R.id.toolbar);
        back.setOnClickListener(this);
        getRecord();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.toolbar:
              RechargeRecordActivity.this.finish();
                break;
    }
        }
        //获得充值记录
        private void getRecord(){
            OkGo.post(Constants.URL_BASE+"recharge?action=recharge_record ")
                    .execute(new StringCallback() {
                        @Override
                        public void onSuccess(String s, Call call, Response response) {
                            System.out.print("充值记录=="+s);
                            try {
                                List<Map<String, Object>> mlist=new ArrayList<>();
                                JSONArray jsonArray = new JSONArray(s);
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    JSONObject jsonObject=jsonArray.getJSONObject(i);
                                    Map<String,Object> map=new HashMap<>();
                                    map.put("createtime",jsonObject.getString("createtime"));
                                    map.put("type",jsonObject.getString("type"));
                                    map.put("money",jsonObject.getString("money"));
                                    mlist.add(map);
                                }
                                recordAdapter = new RecordAdapter(RechargeRecordActivity.this, mlist);
                                recycleView.setAdapter(recordAdapter);

                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                        }
                    });
        }
}
